{:token()}
<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">文章标题</label>
    <div class="am-u-sm-9">
         <input class="am-form-field" type="text" name="title" value="{$record.title}" />
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">文章封面</label>
    <div class="am-u-sm-9">
        <div class="am-form-group am-form-file">
            <button type="button" class="am-btn am-btn-danger am-btn-sm" id="filePicker2">
                <i class="am-icon-cloud-upload"></i> 上传文章封面(200*200)</button>
            <div class="uploader-list2" style="margin-top: 10px;">
                {if condition="$record.cover"}
                <img src="{$record.cover}" width="200px" />
                {/if}
            </div>
            <input type="hidden" name="cover" value="{$record.cover}"/>
        </div>
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">文章简介</label>
    <div class="am-u-sm-9">
        <textarea name="intro" style="height:200px;">{$record.intro}</textarea>
    </div>
</div>


<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">文章链接</label>
    <div class="am-u-sm-9">
        <input class="am-form-field" type="text" name="link" value="{$record.link}" />
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">是否可用</label>
    <div class="am-u-sm-9">
        <div class="tpl-switch">
            <input type="checkbox" name="status" class="ios-switch bigswitch tpl-switch-btn" {neq  name="$record.status" value="0"}checked{/neq} />
            <div class="tpl-switch-btn-view"><div></div></div>
        </div>
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">是否置顶</label>
    <div class="am-u-sm-9">
        <div class="tpl-switch">
            <input type="checkbox" name="is_top" class="ios-switch bigswitch tpl-switch-btn" {eq name="$record.is_top" value="1"}checked{/eq} />
            <div class="tpl-switch-btn-view"><div></div></div>
        </div>
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">文章排序</label>
    <div class="am-u-sm-9">
        <input type="text" name="sort" placeholder="文章排序" value="{$record.sort}">
        <p class="am-form-help">数值越大越靠前,最大值127</p>
    </div>
</div>

<div class="am-form-group">
    <div class="am-u-sm-9 am-u-sm-push-3">
        <button type="button" class="am-btn am-btn-primary form-btn">保存修改</button>
        <button type="button" class="am-btn" onclick="history.go(-1);">取消</button>
    </div>
</div>

<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">错误信息</div>
        <div class="am-modal-bd error_msg">
            Hello world！
        </div>
        <div class="am-modal-footer">
            <span class="am-modal-btn">确定</span>
        </div>
    </div>
</div>

<div class="am-modal am-modal-loading am-modal-no-btn" tabindex="-1" id="my-modal-loading">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">正在载入...</div>
        <div class="am-modal-bd">
            <span class="am-icon-spinner am-icon-spin"></span>
        </div>
    </div>
</div>
<style type="text/css">
    .webuploader-element-invisible {
        position: absolute ;
        clip: rect(1px 1px 1px 1px);
        top: -5px;
        left: -15px;
    }
    .file-item{margin-top: 10px;}
</style>
<script type="text/javascript" src="__PUBLIC__/admin/webuploader/webuploader.html5only.min.js"></script>
<script type="text/javascript">

    var cover = WebUploader.create({

        // 选完文件后，是否自动上传。
        auto: true,

        // 文件接收服务端。
        server: '{:url("files/upload",["path"=>"cover"])}',

        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: {id:'#filePicker2',multiple:false},

        // 只允许选择图片文件。
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/gif,image/jpeg,image/jpg,image/png,image/svg'
        }

    });

    cover.on( 'fileQueued', function( file ) {
        var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<img>' +
                '<div class="info">' + file.name + '</div>' +
                '</div>'
            ),
            $img = $li.find('img');


        // $list为容器jQuery实例
        $('.uploader-list2').html( $li );

        // 创建缩略图
        // 如果为非图片文件，可以不用调用此方法。
        // thumbnailWidth x thumbnailHeight 为 100 x 100
        cover.makeThumb( file, function( error, src ) {
            if ( error ) {
                $img.replaceWith('<span>不能预览</span>');
                return;
            }

            $img.attr( 'src', src );
        }, 200, 200 );
    });

    // 文件上传过程中创建进度条实时显示。
    cover.on( 'uploadProgress', function( file, percentage ) {
        $.AMUI.progress.start();
    });

    // 文件上传成功，给item添加成功class, 用样式标记上传成功。
    cover.on( 'uploadSuccess', function( file ,data) {
        var input = $('input[name=cover]');
        input.val( '__PUBLIC__'+data.url );
    });

    // 完成上传完了，成功或者失败，先删除进度条。
    cover.on( 'uploadComplete', function( file ) {
        $.AMUI.progress.done();
    });

    $('.form-btn').click(function(){

        var form = $(this).parents('form');
        var url = form.attr('action');
        var formData = form.serializeArray();
        $.ajax({
            url:url,
            type:'post',
            data:formData,
            dataType:'json',
            success:function(result){
                if(result.code == 0){
                    $('.am-modal-hd').text(result.message);
                    $('#my-modal-loading').modal('open');
                    timed();
                }else{
                    $('.error_msg').text(result.message);
                    $('#my-alert').modal('open');
                }
            }
        });
        return false;
    });

    function timed()
    {
        var t=setTimeout("location.href='{:url($code.'/index',['stage_id'=>$stage_id])}'",1000);
    }

</script>